package com.example.binpacking.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.binpacking.mapper.InterviewerMapper;
import com.example.binpacking.mapper.SysmasterMapper;
import com.example.binpacking.mapper.TeacherMapper;
import com.example.binpacking.service.OperationLoginTableInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class OperationLoginTableInformationServiceImpl implements OperationLoginTableInformationService {
    @Autowired
    private SysmasterMapper sysMasterMapper;
    @Autowired
    private TeacherMapper teacherMapper;
    @Autowired
    private InterviewerMapper interviewMapper;
    @Override
    public Object handleRequest(String usetype, BigDecimal loginid, String action) throws Exception {
        switch (usetype) {
            case "f":
                return handleAction(interviewMapper, action, loginid);
            case "s":
                return handleAction(sysMasterMapper, action, loginid);
            case "t":
                return handleAction(teacherMapper, action, loginid);
            default:
                throw new IllegalArgumentException("Invalid usetype");
        }
    }

    @Override
    public <T> Object handleAction(BaseMapper<T> mapper, String action, BigDecimal loginid) {
        switch (action) {
            case "add":
                // Implement add logic
                break;
            case "edit":
                // Implement edit logic
                break;
            case "see":
                QueryWrapper<T> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("loginid", loginid);
                return mapper.selectList(queryWrapper);
            default:
                throw new IllegalArgumentException("Invalid action");
        }
        return null;
    }
}
